<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>报价单信息</legend>
            <div style="margin: 3px 3px 3px 3px">
                <form class="layui-form layuimini-form" action="">
                    <input type="text" name="id" id="id" style="display: none"
                           class="layui-input">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">报价单名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="quotationName" id="quotationName"
                                       value="" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label required">报价单编号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="quotationNo" id="quotationNo"
                                       lay-verify="required" value="" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label required">客人:</label>
                            <div class="layui-input-inline">
                                <select lay-verify="required" name="customerId" id="customerId" lay-search="">
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">报价时间</label>
                            <div class="layui-input-inline">
                                <input readonly="readonly" type="text" class="layui-input" name="quotationTime"
                                       id="quotationTime">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">币别</label>
                            <div class="layui-input-inline">
                                <input type="text" name="currencyCode" id="currencyCode"
                                       value="" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">FOR港口</label>
                            <div class="layui-input-inline">
                                <input type="text" name="harborFor" id="harborFor"
                                       value="" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">备注</label>
                            <div class="layui-input-inline">
                                <input type="text" name="remark" id="remark"
                                       value="" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="save-quotation">
                                保存报价单
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

    </div>
</div>
<script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/static/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="/static/lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
<script src="/static/js/common.js"></script>
<script>
    let ids = $.common.getUrlParam("ids");
    ids  = decodeURIComponent(ids);
    layui.use(['form', 'laydate', 'util'], function () {
        var form = layui.form,
            laydate = layui.laydate;
        util = layui.util;
        var now = new Date();
        //初始化时间
        laydate.render({
            elem: '#quotationTime'
            , type: 'date',
            value: new Date()
        });
        //初始化下拉框 客人
        let callback = {
            onSuccess: function (result) {
                if (result.code == '0') {
                    $('#customerId').append(new Option('请选择', '', true));// 下拉菜单里添加元素
                    $.each(result.data, function (index, item) {
                        let option = new Option(item.customerName, item.id);
                        if (customerId) {
                            if (item.id == customerId) {
                                option.selected = true;
                            }
                        }
                        $('#customerId').append(option);// 下拉菜单里添加元素
                    });
                } else {
                    $.common.showErrorMessage(result.message)
                    return false;
                }
            }
        };
        $.xAjax('/customer/select', 'POST', JSON.stringify({}), callback);
        //合同下拉框
        let callback1 = {
            onSuccess: function (result) {
                if (result.code == '0') {
                    $('#contractId').append(new Option('请选择', '', true));// 下拉菜单里添加元素
                    $.each(result.data, function (index, item) {
                        let option = new Option(item.contractName, item.id);
                        $('#contractId').append(option);// 下拉菜单里添加元素
                    });
                } else {
                    $.common.showErrorMessage(result.message)
                    return false;
                }
            }
        };
        $.xAjax('/contract/select', 'POST', JSON.stringify({}), callback1);
        //初始化下拉框
        form.render("select");
        // 监听报价单提交
        form.on('submit(save-quotation)', function (data) {
            let url = "/quotation/saveOrUpdate"
            let callback = {
                onSuccess: function (result) {
                    if (result.code == '0') {
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.location.reload();
                        parent.layer.close(iframeIndex);
                    } else {
                        $.common.showErrorMessage(result.message)
                        return false;
                    }
                }
            };
            data.field.itemIds=JSON.parse(ids);
            data.field.quotationTime = util.toDateString(data.field.quotationTime, 'yyyy-MM-dd HH:mm:ss');
            $.xAjax(url, 'POST', JSON.stringify(data.field), callback);
            return false;
        });
    });
</script>
</body>
</html>
